package com.yitiao.ratelimit;

import lombok.SneakyThrows;

public class SlidingWindowRateLimiterTest {
    @SneakyThrows
    public static void main(String[] args) {
        SlidingWindowRateLimiter rateLimiter = new SlidingWindowRateLimiter(5000, 4); // 设置滑动窗口大小为1秒，限流阈值为10

        for (int i = 0; i < 15; i++) {
            boolean allowed = rateLimiter.allowRequest();
            System.out.println("Request " + (i + 1) + ": " + (allowed ? "Allowed" : "Rejected"));
            if (i%5==0){
                Thread.sleep(5000);
            }else {
                Thread.sleep(1000);
            }
        }
    }
}
